/*
 * AutoDeleteTree.h
 *
 *  Created on: 2014. 7. 4.
 *      Author: jjaehuny
 */

#ifndef FRAMEWORK_DATASTRUCTURE_AUTODELETETREE_H_
#define FRAMEWORK_DATASTRUCTURE_AUTODELETETREE_H_

#include <map>

namespace Framework { namespace DataStructure {

template<class Key, class Value>
class AutoDeleteTree
{
public:
	AutoDeleteTree();
	~AutoDeleteTree();

	AutoDeleteTree(const AutoDeleteTree & other) = delete;
	AutoDeleteTree & operator= (const AutoDeleteTree & other) = delete;

	bool Regist(Key key, Value * pValue);
	Value * Get(Key key);

private:
	std::map<Key, Value *> clsTree_;
};

template<class Key, class Value>
AutoDeleteTree<Key, Value>::AutoDeleteTree()
{

}

template<class Key, class Value>
AutoDeleteTree<Key, Value>::~AutoDeleteTree()
{
	for (auto itr : clsTree_)
	{
		delete itr.second;
	}
}

template<class Key, class Value>
bool
AutoDeleteTree<Key, Value>::Regist(Key key, Value * pValue)
{
	auto itr = clsTree_.find(key);
	if (itr != clsTree_.end())
		return false;

	clsTree_[key] = pValue;

	return true;
}

template<class Key, class Value>
Value *
AutoDeleteTree<Key, Value>::Get(Key key)
{
	auto itr = clsTree_.find(key);
	if (itr == clsTree_.end())
		return NULL;

	return itr->second;
}

} /*DataStructure*/ } /*Framework*/

#endif /* AUTODELETETREE_H_ */
